//
//  ioTest.cpp
//  class
//
//  Created by Threese on 2019/7/23.
//  Copyright © 2019 Threese. All rights reserved.
//

#include <iostream>
#include "CPlan.h"
#include "CTimeLine.h"
#include "CTask.h"
#include "CDate.h"
#include "IOFunction.h"

using namespace std;

int main( ){
    CPlan *plan = new CPlan;
    plan->setName("plan1");
    plan->addLabel("plan");
    plan->addLabel("nono");
    plan->addLabel("suck");
    plan->setRemarks("remarrrrrrks");
    
    CTimeLine *timeline = new CTimeLine;
    timeline->setName("timeline");
    plan->addTimeLine(timeline);
    
    CTask *task1 = new CTask;
    task1->setName("task1");
    task1->addLabel("lbl1");
    task1->addLabel("lbl2");
    task1->setRemarks("remarrrrrrks");
    
    IDate *sDate = new CDate;
    sDate->setDate(2000, 01, 01, 23, 19, 10);
    task1->setStartDate(*sDate);
    IDate *eDate = new CDate;
    eDate->setDate(2020, 03, 01, 12, 32, 11);
    task1->setEndDate(*eDate);
    
    task1->setImportance(1);
    
    CTask *task2 = new CTask;
    task2->setName("task2");
    task2->addLabel("lbl1");
    task2->addLabel("lbl2");
    task2->setRemarks("remarrrrrrks\nfuckyou mohterfucker\nyou are son of a bitch\n");
    sDate->setDate(2000, 01, 01, 23, 19, 10);
    task2->setStartDate(*sDate);
    eDate->setDate(2020, 03, 01, 12, 32, 11);
    task2->setEndDate(*eDate);
    
    task2->setImportance(1);
    
    timeline->addTask(task1);
    timeline->addTask(task2);
    
    ctrlSave("t1.txt", plan);
    
    cout << "**** NNND" << endl;
    
    ifstream fin;
    fin.open("t1.txt");
    
    string buff;
    while(!fin.eof()){
        getline(fin, buff);
        cout << buff << endl;
    }
    
    cout << endl << endl;
    IPlan* ip = ctrlOpen("t1.txt");
    
    while(ip){
        cout << ip->getName() << "fuck" << endl;
        cout << ip->getLabel() << endl;
        cout << ip->getRemarks() << endl;
        
        ITimeLine* itl = ip->getTimeLine(0);
        while(itl){
            cout << itl->getName() << endl;
            
            ITask* it = itl->getTask();
            while(it){
                cout << it->getName() << endl;
                cout << it->getLabel() << endl;
                cout << it->getRemarks() << endl;
                IDate *id = it->getStartDate();
                cout << id->getYear() << " " << id->getMonth() << " " << id->getDay() << " "
                << id->getHour() << " " << id->getMinute() << " " << id->getSecond() << endl;
                id = it->getEndDate();
                cout << id->getYear() << " " << id->getMonth() << " " << id->getDay() << " "
                << id->getHour() << " " << id->getMinute() << " " << id->getSecond() << endl;
                cout << it->getImportance() << endl;
                
                it = const_cast<ITask*>(it->getNext());
            }
            
            itl = const_cast<ITimeLine*>(itl->getNext());
        }
        ip = const_cast<IPlan*>(ip->getNext());
    }
}
